package com.book.bookshop.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //默认路径改成指定路径  虚拟路径
        //Linux
//        registry.addResourceHandler("/public/**").addResourceLocations("file:/usr/uploadfile/images/");
        //Windows
        registry.addResourceHandler("/public/**").addResourceLocations("file:/D:/images/");
//        registry.addResourceHandler("/public/**").addResourceLocations("file:\\static\\images\\");
    }

    /**
     * 配置跨域
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**").allowedOrigins("http://localhost:80");
    }

    /**
     * 过滤器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/order/**","/cart/**");
    }
}
